package com.yao.mall.config;

import com.yao.mall.interceptor.LoginInterceptor;
import com.yao.mall.interceptor.RefreshLoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author jiahua.yao
 * @version 1.0
 * @description 拦截器配置
 * @date 2024/3/1 14:46
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //knife4j允许的接口
        // "/goods/detail",暂不释放
        String[] excludePatterns = new String[]{"/swagger-resources/**", "/webjars/**", "/v3/**", "/swagger-ui.html/**",
                "/api", "/api-docs", "/api-docs/**", "/doc.html/**"};
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/carousel/get",
                        "/goodsSku/**",
                        "/brand/**",
                        "/goods/get",
                        "/goods/basic",
                        "/category/**",
                        "/user/register",
                        "/user/login",
                        "/user/sendLoginCode",
                        "/user/sendRegCode",
                        "/goods/hotGoods",
                        "/error",
                        "/user/sendPhoneCode",
                        "/pay/aliPay",
                        "/pay/notify",
                        "/user/logout"
                ).excludePathPatterns(excludePatterns).order(1);
        //order代表拦截器的执行顺序，order越大越后执行
        registry.addInterceptor(new RefreshLoginInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }

}
